package com.unbank.rest;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

import org.springframework.stereotype.Component;

import com.google.gson.Gson;
import com.unbank.entity.News;
import com.unbank.search.SearchClient;
import com.unbank.search.SearchErrorInfo;
@Component
@Path("/ESOnlySearch")
public class ESOnlySearchService {
	
	@Path("/searchByMultiCondition")
	@GET
	public String searchByMultiCondition(@QueryParam("contentWord") String contentWord,
			@QueryParam("keyword") String keyword,
			@QueryParam("tagName") String tagName,
			@QueryParam("pageSize") String pageSize,
			@QueryParam("from") String from) {
		SearchClient searchClient = new SearchClient();
		Integer size = 20;
		Integer f = 0;
		try {
			if (pageSize != null) {
				size = Integer.valueOf(pageSize);
			}
			if (from != null) {
				f = Integer.valueOf(from);
			}
			
			if(contentWord==null&&keyword==null&&tagName==null){
				return SearchErrorInfo.ILLEGALARGS;
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
			// 参数错误
			return SearchErrorInfo.ILLEGALARGS;
		}
		
		List<News> newsList = searchClient.SearchByMultiCondition(contentWord,keyword,tagName, f, size);
		Gson gson = new Gson();
		return gson.toJson(newsList);
	}
}
